package process

import (
	"public_security/controllers"
	"public_security/models"
	"public_security/models/process"
)

// 值班备勤 API
type ProcessController struct {
	controllers.BaseController
}

func (i *ProcessController) Prepare() {
	i.BasePrepare()
}

// @Title create
// @Description 创建排班
// @Param	body		body 	models.Process	 true		"请求参数"
// @Success 200 success
// @router /create [post]
func (i *ProcessController) Create() interface{} {
	art := new(models.Process)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = process.Create(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "创建成功")
}

// @Title update
// @Description 修改排班
// @Param	body		body 	models.Process	 true		"请求参数"
// @Success 200 success
// @router /update [post]
func (i *ProcessController) Update() interface{} {
	art := new(models.Process)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = process.Update(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "修改成功")
}

// @Title remove
// @Description 删除排班
// @Param	body		body 	models.Process	 true		"请求参数"
// @Success 200 success
// @router /remove [post]
func (i *ProcessController) Remove() interface{} {
	art := new(models.Process)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = process.Remove(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "删除成功")
}

// @Title query
// @Description 查询排班
// @Param	body		body 	models.Process	 true		"请求参数"
// @Success 200 {object} models.Process
// @router /query [post]
func (i *ProcessController) Query() interface{} {
	art := new(models.Process)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	results := process.Query(art)
	return i.ToMessageSuccess(results, "查询成功")
}
